package com.ruoyi.examination.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.examination.domain.QuestionGroupRelation;
import com.ruoyi.examination.service.IQuestionGroupRelationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 试题题组关系Controller
 * 
 * @author hcc
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/questionGroupRelation")
public class QuestionGroupRelationController extends BaseController
{
    @Autowired
    private IQuestionGroupRelationService questionGroupRelationService;

    /**
     * 查询试题题组关系列表
     */
    @RequiresPermissions("examination:questionGroupRelation:list")
    @GetMapping("/list")
    public TableDataInfo list(QuestionGroupRelation questionGroupRelation)
    {
        startPage();
        List<QuestionGroupRelation> list = questionGroupRelationService.selectQuestionGroupRelationList(questionGroupRelation);
        return getDataTable(list);
    }

    /**
     * 导出试题题组关系列表
     */
    @RequiresPermissions("examination:questionGroupRelation:export")
    @Log(title = "试题题组关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionGroupRelation questionGroupRelation)
    {
        List<QuestionGroupRelation> list = questionGroupRelationService.selectQuestionGroupRelationList(questionGroupRelation);
        ExcelUtil<QuestionGroupRelation> util = new ExcelUtil<QuestionGroupRelation>(QuestionGroupRelation.class);
        util.exportExcel(response, list, "试题题组关系数据");
    }

    /**
     * 获取试题题组关系详细信息
     */
    @RequiresPermissions("examination:questionGroupRelation:query")
    @GetMapping(value = "/{questionGroupId}")
    public AjaxResult getInfo(@PathVariable("questionGroupId") String questionGroupId)
    {
        return success(questionGroupRelationService.selectQuestionGroupRelationByQuestionGroupId(questionGroupId));
    }

    /**
     * 新增试题题组关系
     */
    @RequiresPermissions("examination:questionGroupRelation:add")
    @Log(title = "试题题组关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionGroupRelation questionGroupRelation)
    {
        return toAjax(questionGroupRelationService.insertQuestionGroupRelation(questionGroupRelation));
    }

    /**
     * 修改试题题组关系
     */
    @RequiresPermissions("examination:questionGroupRelation:edit")
    @Log(title = "试题题组关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionGroupRelation questionGroupRelation)
    {
        return toAjax(questionGroupRelationService.updateQuestionGroupRelation(questionGroupRelation));
    }

    /**
     * 删除试题题组关系
     */
    @RequiresPermissions("examination:questionGroupRelation:remove")
    @Log(title = "试题题组关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionGroupIds}")
    public AjaxResult remove(@PathVariable String[] questionGroupIds)
    {
        return toAjax(questionGroupRelationService.deleteQuestionGroupRelationByQuestionGroupIds(questionGroupIds));
    }
}
